<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>

</head>
<body>
<nav class="navbar navbar-inverse" role="navigation" th:fragment="navbar">
    <div class="container">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                    data-target="">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" th:href="@{/}">Thymeleaf示例</a>
        </div>
        <!--判断用户是否登录 -->
        <div class="collapse navbar-collapse" th:switch="${session.user ==null}">
            <ul class="nav navbar-nav">
                <li><a th:href="@{/user/showUsers}">用户页面</a></li>
            </ul>
            <ul th:case="false" class="nav navbar-nav navbar-right">
                <li class="dropdown">
                    <a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
                       aria-expanded="false">[[${session.user.name?:'默认用户'}]]<span class="caret"></span></a>
                    <ul class="dropdown-menu">
                        <li><a th:href="@{/user/logout}">注销</a></li>
                    </ul>
                </li>
            </ul>

            <form th:case="true" class="navbar-form navbar-right"
                  method="post" th:action="@{/user/login}">
                <div class="form-group">
                    <input type="text" name="name" placeholder="用户名"
                           class="form-control" th:value="'默认用户'">
                </div>
                <button type="submit" class="btn btn-success">登录</button>
            </form>
        </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
</nav>
</body>
</html>